#! /usr/bin/python
import sys
import os

colSize=1
cmd = ""
result=""

cmd ="mkdir result"
os.system(cmd)

cmd ="mkdir result/time"
os.system(cmd)

cmd ="mkdir result/event"
os.system(cmd)

cmd ="mkdir result/cpu"
os.system(cmd)

distinct = 200000
cmd= "rm -rf gbTable* gbKey"
os.system(cmd)
cmd = "./aggBinaryGen 1 10 4  " + str(distinct)
os.system(cmd)
cmd = "chmod 777 gbTable* gbKey"
os.system(cmd)

for colNum in range(1,11):

    result = "result/time/" + str(colNum) + "_noprof" 
    cmd = "./aggTest gbTable " + str(colNum) + " 4 " + str(distinct) + " > " + result
    os.system(cmd)
    os.system(cmd)

    result = "result/time/" + str(colNum) 
    cmd = "nvprof ./aggTest gbTable " + str(colNum) + " 4 " + str(distinct) + " > " + result
    os.system(cmd)
    os.system(cmd)

    result = "result/event/" + str(colNum) + "_mem_request" 
    cmd = "nvprof --events gld_request,gst_request ./aggTest gbTable " + str(colNum) + " 4 " + str(distinct) + " > " + result
    os.system(cmd)

    result = "result/event/" + str(colNum) + "_mem_ld_transaction" 
    cmd = "nvprof --events l1_global_load_hit,l1_global_load_miss ./aggTest gbTable " + str(colNum) + " 4 " + str(distinct) + " > " + result
    os.system(cmd)

    result = "result/event/" + str(colNum) + "_mem_st_transaction" 
    cmd = "nvprof --events global_store_transaction ./aggTest gbTable " + str(colNum) + " 4 " + str(distinct) + " > " + result
    os.system(cmd)

    result = "result/event/" + str(colNum) + "_inst" 
    cmd = "nvprof --events inst_issued,inst_executed ./aggTest gbTable " + str(colNum) + " 4 " + str(distinct) + " > " + result
    os.system(cmd)

cmd= "rm -rf gbTable* gbKey"
os.system(cmd)
